import { ref, onUnmounted } from "vue";
export function useFullLoading(nuxtApp: any) {
	const loading = ref(true);
	const setupListeners = () => {
		nuxtApp.hook("page:start", function () {
			loading.value = true;
		});

		nuxtApp.hook("page:finish", function () {
			loading.value = false;
		});
	};
	setupListeners();
	// 清除hook以避免内存泄漏
	onUnmounted(() => {
		nuxtApp.hook("page:start", () => {}, { prepend: true }); // 使用prepend: true来移除已添加的hook
		nuxtApp.hook("page:finish", () => {}, { prepend: true });
	});
	return {
		loading
	};
}
